﻿@model Inscriptionem.Areas.Inscriptionem.Models.Views.ContactSearchCollectionViewModel

@{
    ViewBag.Title = "Inscriptionem » Contact";
    Layout = "../Shared/Layout.cshtml";

    ViewBag.CurrentPage = "Contact";

    bool isSearchSuccessful = Model.Contacts.Any();

    var itemsCount = Model.Contacts.Count();
    itemsCount = itemsCount / 25 + itemsCount % 25;

    if (itemsCount < Model.Page)
    {
        Model.Page = itemsCount;
    }
    
    int currentPage = Model.Page + 1;
    int totalPages = (Model.Contacts.Count() / 25) + 1;
}

<div class="outer" id="contentwrap">
    @{Html.RenderPartial("NavigationMenu");}
    <div class="postcont">
		<div id="content">
            <div class="post type-post status-publish format-standard hentry">
                <h2 class="title">Contact</h2>
                <div style="float: right; margin-top: -25px;">
                    <form action="/Inscriptionem/Contact/Search" method="post">
                        <input type="text" name="Text" value="@Model.Text" />
                        <input type="hidden" name="Page" value="@(Model.Page + 1)" />
                        <input type="submit" value="Search" />
                    </form>
                </div>
                <div class="postdate-single error-message">@(isSearchSuccessful ? string.Empty : "Nothing found!")</div>

                @if (isSearchSuccessful)
                { 
                <text>
                <table width="100%">
                    <thead>
                        <tr class="postdate">
                            <td>Member</td>
                            <td>Mail</td>
                            <td>Message</td>
                            <td>Is Replied</td>
                            <td style="width: 60px;"></td>
                            <td style="width: 60px;"></td>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach (var contact in Model.Contacts.Skip(25 * Model.Page).Take(25))
                    {
                    <text>
                    <tr>
                        <td>@(contact.Member == null ? "N/A" : contact.Member.FirstName + " " + contact.Member.LastName)</td>
                        <td>@contact.Mail</td>
                        <td>@(contact.Message.Length < 25 ? contact.Message : contact.Message.Substring(0, 25))</td>
                        <td><input type="checkbox" @(contact.ContactResponses.Any() ? "checked" : string.Empty) disabled="disabled" /></td>
                        <td>
                            <form method="post" action="/Inscriptionem/Contact/Reply">
                                <input type="hidden" name="ID" value="@contact.ID" />
                                <input type="submit" value="Reply" />
                            </form>
                        </td>
                        <td>
                            <form method="post" action="/Inscriptionem/Contact/Delete">
                                <input type="hidden" name="Page" value="@Model.Page" />
                                <input type="hidden" name="ID" value="@contact.ID" />
                                <input type="submit" value="Delete" />
                            </form>
                        </td>
                    </tr>
                    </text>
                    }
                    </tbody>
                </table>
                </text>
                }
			</div>
        </div>
	</div>	
</div>
